package Model;

import java.io.*;
import java.util.*;

import View.Interface;

public class contactList {
	public ArrayList list;
	
	public contactList() {
		list = new ArrayList<Contact>();
		
	}
	
	public ArrayList load() {
		
		FileInputStream file;
		try {
			file = new FileInputStream("contacts.csv");
			BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(file)));
			String read = new String();
			read = br.readLine(); //Skip first line
			
			while ((read = br.readLine()) != null)
			{
				StringTokenizer str = new StringTokenizer(read, ";"); 
				Contact contactAdd = new Contact();
				contactAdd.listContactField.put(Model.FIRST_NAME, str.nextToken());
				contactAdd.listContactField.put(Model.LAST_NAME, str.nextToken());
				contactAdd.listContactField.put(Model.HOME_ADDRESS, str.nextToken());
				contactAdd.listContactField.put(Model.COMPANY_ADDRESS, str.nextToken());
				contactAdd.listContactField.put(Model.PERSONAL_MOBILE_PHONE, str.nextToken());
				contactAdd.listContactField.put(Model.PERSONAL_HOME_PHONE, str.nextToken());
				contactAdd.listContactField.put(Model.PRO_MOBILE_PHONE, str.nextToken());
				contactAdd.listContactField.put(Model.PRO_OFFICE_PHONE, str.nextToken());
				contactAdd.listContactField.put(Model.HOMEPAGE, str.nextToken());
				contactAdd.listContactField.put(Model.PRO_EMAIL, str.nextToken());
				contactAdd.listContactField.put(Model.PERSONAL_EMAIL, str.nextToken());
				contactAdd.listContactField.put(Model.OTHER_IM, str.nextToken());
				contactAdd.listContactField.put(Model.OTHER_SKYPE, str.nextToken());
				contactAdd.dateAdded = str.nextToken();
				contactAdd.listContactField.put(Model.GROUP, str.nextToken());
				contactAdd.listContactField.put(Model.PICTURE_PATH, str.nextToken());

				list.add(contactAdd);
			}
			System.out.println("loaded");
			br.close();
			file.close();
			return list;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
}
